package com.activities;


import com.example.lizhiinformation.R;
import com.fragment.Fragment_ViewPager;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.Toast;
public class MainActivity extends FragmentActivity {
	private int mBackKeyPressedTimes = 0;
	private ImageView welcome;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		
		welcome = (ImageView) findViewById(R.id.welcome);
		
		
		FragmentTransaction beginTransaction = getSupportFragmentManager().beginTransaction();
		Fragment_ViewPager FragmentPager = new Fragment_ViewPager();	
		beginTransaction.replace(R.id.Fragment, FragmentPager);
		beginTransaction.commit();	
		welcome();
	
	}


	public void onBackPressed() {
		// TODO Auto-generated method stub
		if(mBackKeyPressedTimes==0){
			Toast.makeText(MainActivity.this, "再按一次退出", Toast.LENGTH_SHORT).show();
			mBackKeyPressedTimes=1;
			new Thread(){
				public void run() {
					try {
						Thread.sleep(2000);
						mBackKeyPressedTimes=0;
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					
				};
			}.start();
			
			return;	
		}
		else {
			MainActivity.this.finish();
		}
		
	}
	public void welcome(){
		final Handler handler = new Handler(){
			@Override
			public void handleMessage(Message msg) {
				// TODO Auto-generated method stub
				super.handleMessage(msg);
				if(msg.what==0){
					welcome.setVisibility(View.GONE);
				}
				
			}
		};
		new Thread(){
			public void run() {
				try {
					
					Thread.sleep(5000);
					Message message = new Message();
					handler.sendEmptyMessage(0);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			};
		}.start();
	}
}
